/**
 * @File AccountingSetupController.java


 * @author Agam Bhamra
 * @Version 1.0
 * @Date July 31, 2013
 * 
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproducuce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.generalLedger.accountingSetup;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Controller;

import flex.messaging.FlexContext;
import flex.messaging.FlexSession;

@Controller
@RemotingDestination("accountingSetupController")

public class AccountingSetupController {
	@Autowired
	@Qualifier("AccountingSetupDaoImpl")
	
	private AccountingSetupDao accountingSetupDao;
	
	public String addLegalEntity(Map<String, String> obj)
	{
		String status="";
		AccountingSetupInfoBean input = new AccountingSetupInfoBean();
		FlexSession session = FlexContext.getFlexSession();
		input.setUserId(session.getAttribute("userId").toString());
		input.setCountry(obj.get("country"));
		input.setLegalEntityName(obj.get("legalEntityName"));
		input.setOrganizationName(obj.get("organizationName"));
		input.setLegalEntityIdentifier(obj.get("legalEntityIdentifier"));
//		input.setEinTin(obj.get("einTin"));
		input.setTransactionEntity(obj.get("transactionEntity"));
		input.setLegalAddress(obj.get("legalAddress"));
//		input.setPlaceOfRegistration(obj.get("placeOfRegistration"));
//		input.setInceptionDate(obj.get("inceptionDate"));
//		input.setNaics(obj.get("naics"));
//		input.setTypeOfCompany(obj.get("typeOfCompany"));
		status = accountingSetupDao.addLegalEntity(input);
		return status;
	}
	
	public List<AccountingSetupInfoBean> getLegalEntities()
	{
		List<AccountingSetupInfoBean> legalEntities = new ArrayList<AccountingSetupInfoBean>();
		legalEntities = accountingSetupDao.getLegalEntities();
		return legalEntities;
	}
	
	public List<AccountingSetupInfoBean> getChartOfAccounts()
	{
		List<AccountingSetupInfoBean> chartOfAccounts = new ArrayList<AccountingSetupInfoBean>();
		chartOfAccounts = accountingSetupDao.getChartOfAccounts();
		return chartOfAccounts;
	}
	
	public List<AccountingSetupInfoBean> getAccountingCalendar()
	{
		List<AccountingSetupInfoBean> accountingCalendar = new ArrayList<AccountingSetupInfoBean>();
		accountingCalendar = accountingSetupDao.getAccountingCalendar();
		return accountingCalendar;
	}
	
	public List<AccountingSetupInfoBean> getCurrency()
	{
		List<AccountingSetupInfoBean> currency = new ArrayList<AccountingSetupInfoBean>();
		currency = accountingSetupDao.getCurrency();
		return currency;
	}
	
	public String saveAccoutingSetup(Map<String, String> obj)
	{
		String status="";
		AccountingSetupInfoBean input = new AccountingSetupInfoBean();
		FlexSession session = FlexContext.getFlexSession();
		input.setUserId(session.getAttribute("userId").toString());
		input.setType(obj.get("type"));
		input.setName(obj.get("name"));
		input.setCoaId(obj.get("coaId"));
		input.setLegalEntityIdentifier(obj.get("legalEntityIdentifier"));
		input.setAccCalType(obj.get("accCalType"));
		input.setLegalAddress(obj.get("legalAddress"));
		input.setCurrencyCode(obj.get("currencyCode"));
		input.setSubAccMethod(obj.get("subAccMethod"));
		status = accountingSetupDao.saveAccoutingSetup(input);
		return status;
	}
	
	public List<AccountingSetupInfoBean> getLedgers()
	{
		List<AccountingSetupInfoBean> ledgers = new ArrayList<AccountingSetupInfoBean>();
		ledgers = accountingSetupDao.getLedgers();
		return ledgers;
	}

}
